<!DOCTYPE html>
<html xmlns="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<base th:href="@{/}"/>
<title>Insert title here</title>
<link rel="stylesheet" th:href="@{/css/bootstrap.min.css}"/>
<link rel="stylesheet" th:href="@{/css/Managerstyle.css}"/>
<script th:src="@{/js/jquery-3.4.1.min.js}"></script>
<script th:src="@{/js/bootstrap.min.js}"></script>
</head>
<body>
	<div class="contain">
		<h1 th:text="|当前学期： ${currentterm.term.termName}|"></h1>
		<h3>学期管理</h3>
		<table class="table table-hover">
			<tr>
				<td>年份</td>
				<td>学期顺序</td>
				<td>学期名称</td>
				<td>是否可上传成绩</td>
				<td>是否可评教</td>
				<td>是否可选课</td>
				<td>操作</td>
			</tr>
			<tr align="center" th:each="term:${termlist}" th:id="|tr${term.termId}|">
				<td th:text="${term.tyear}"></td>
				<td th:text="${term.term}"></td>
				<td th:text="${term.termName}"></td>
				<td th:text="${term.uploadgrade}==1?'是':''"></td>
				<td th:text="${term.assess}==1?'是':''"></td>
				<td th:text="${term.signup}==1?'是':''"></td>
				<td>
					<a th:href="|mc/to_modifyTerm/${term.termId}|">编辑</a>
					<a th:href="|javascript:deleteterm(${term.termId});|">删除</a>
					<a th:href="|mc/modifyCurrentTerm/${term.termId}|">设置为当前学期</a>
				</td>
				
			</tr>
		</table>
		<!-- Button trigger modal -->
		<button type="button" class="btn btn-success" data-toggle="modal" data-target="#addTerm">
		  添加新学期
		</button>
		<div class="text-center">
			<nav>
				<ul class="pagination">
					<li><a th:href="@{/mc/getAllTerm/(pageNo=1)}">首页</a></li>
					<li><a th:href="@{/mc/getAllTerm/(pageNo=${pageInfo.hasPreviousPage}?${pageInfo.prePage}:1)}">上一页</a></li>
					<li th:each="page:${pageInfo.navigatepageNums}">
						<a th:class="${pageInfo.pageNum}==${page}?'active'"
						   th:href="@{/mc/getAllTerm/(pageNo=${page})}">[[${page}]]</a>
					</li>
					<li><a th:href="@{/mc/getAllTerm/(pageNo=${pageInfo.hasNextPage}?${pageInfo.nextPage}:${pageInfo.pages})}">下一页</a></li>
					<li><a th:href="@{/mc/getAllTerm/(pageNo=${pageInfo.pages})}">尾页</a></li>
				</ul>
			</nav>
		</div>
		<br>
		<!-- addTerm -->
		<div class="modal fade" id="addTerm" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
		  <div class="modal-dialog" role="document">
		    <div class="modal-content">
		      <div class="modal-header">
		        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
		        <h4 class="modal-title" id="myModalLabel">添加新学期</h4>
		      </div>
		      <form action="mc/addTerm" method="post">
		      <div class="modal-body">
					<dl class="dl-horizontal">
					  <dt>年份：</dt>
					  <dd>
						  <select id="tyear" name="tyear">
								<option value="2018">2018</option>
								<option value="2019">2019</option>
								<option value="2020">2020</option>
								<option value="2021">2021</option>
								<option value="2022">2022</option>
								<option value="2023">2023</option>
								<option value="2024">2024</option>
						  </select>
					  </dd>
					  <br>
					  <dt>学期：</dt>
					  <dd>
				  		 <select id="term" name="term">
							<option value="1">春</option>
							<option value="2">夏</option>
							<option value="3">秋</option>
						 </select>
					  </dd>
					  <br>
					  <dt>学期名称：</dt>
					  <dd>
				  		  <input name="termName" required="required" maxlength="5" class="form-control" placeholder="例如：xxxx春">
					  </dd>
					</dl>
		      </div>
		      <div class="modal-footer">
		        <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
		        <input type="submit" class="btn btn-primary" value="添 加">
		      </div>
		      </form>
		    </div>
		  </div>
		</div>
		
		
		
	</div>
	<script>  
            function deleteterm(id) {
                $.ajax({
                    url: 'mc/deleteTerm',
                    type: 'POST',
                    data: {termId: id}, 
                    success: function () {
                    	$("#tr" + id).remove(); 
                    },
                    error: function (req, status, error) {
                        alert("不可删除当前学期！" + error);
                    }
                });
            }
            
    </script>
</body>
</html>